import * as Api from '../../utils/api.js'
var app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    themeColors: '',

    goodsId: '',
    page: 0,
    queryCarList: [],
    rantrecordType: 1,
    isFromSearch: false
  },
  searchScrollLower() {
    console.log('上拉')
    if (this.data.isFromSearch) {
      return
    }
    this.setData({ rantrecordType: 0, page: this.data.page + 1, isFromSearch: true })
    this.queryPdBindCar()
  },
  queryPdBindCar() {
    
    let self = this
    let url = app.globalData.baseUrl1 + '/goods/car/query';
    let data = {
      page: this.data.page,
      pageSize: 20,
      goodsId: this.data.goodsId
    }
    console.log(data)
    let callBack = (res) => {
     
      if (res == null) {

        console.log("网络请求错误！");
        return;
      }
      if (res.data.status != 200) {
        console.log("请求数据错误");
        return;
      }
      let queryCarList = this.data.queryCarList

      if (res.data.data.carList.length != 0) {
        queryCarList.concat()
        res.data.data.carList.forEach((item, index) => {
          queryCarList.push(item)
        })
        this.setData({
          isFromSearch: false
        })
         wx.hideLoading();
      } else {
        self.setData({
          rantrecordType: 2,
        });
        wx.hideLoading();
        return
      }

      this.setData({
        queryCarList: queryCarList,
       
      })
      wx.hideLoading();
      console.log(this.data.queryCarList)



    }
    Api.reqFormPost(url, data, callBack)



  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    if (app.globalData.merchant === null) {
      app.doLogin(this.onLoad, this.onShow, options);
      return
    }
    this.setData({
      goodsId: options.goodsId,
      themeColors: app.globalData.merchant.themeColors
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    if (app.globalData.merchant === null) {
      return
    } 
    if (app.globalData.merchant.mustLogin && app.globalData.userId === null) {
      wx.navigateTo({
        url: '/pages/core/login/login',
        success() {
          wx.showToast({
            title: '请先登陆',
            icon: 'loading',
            duration: 1000
          })
        }
      })
      return
    }
    wx.showLoading({
      mask: true,
      title: '加载中'
    })
    this.queryPdBindCar()
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})